import org.openqa.selenium.internal.Base64Encoder;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class base64 {
    public static String ImageToBase64(String imgPath){
        InputStream in = null;
        byte[] data = null;
        //读取图片
        try {
            in = new FileInputStream(imgPath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Base64Encoder encoder = new Base64Encoder();
        System.out.println(encoder.encode(data));
        return encoder.encode(data);
    }
    public static void main(String[] args) {
       //本地路径
        String imagePath = "D:\\123456.png";
        ImageToBase64(imagePath);
    }

}
